﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - ProgramTask" 
*/ 

component 
	displayname="public.service.db.senate.sequence.ProgramTask" 
	output=false 
	accessors=true 
	{

	property type="string" name="TermID" hint="学期代码";
	property type="string" name="CourseID" hint="课程ID";
	property type="string" name="CourseIndex" hint="课序号";

	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}

	/**
	* @hint "生成计划类教学任务的课序号"
	*/
	public string function getIDX() output=false {
		/* 
			课序号规则 3位代码
		*/
		var nextID = numberFormat(1, "0__");
		
		var sql = "	SELECT
						tsk.cidx
					FROM
						t_task tsk
					WHERE
						tsk.cid = :courseId 
						AND
						tsk.term_id = :termId 
					ORDER BY
						tsk.cidx DESC";

		var queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		queryObj.addParam( name="termId", value=getTermID(), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="courseId", value=getCourseId(), cfsqltype="cf_sql_varchar" );		
		var rs_check = queryObj.execute(sql = sql).getResult();

		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = numberFormat((rs_check.cidx + 1), "0__");
		}

		return nextID;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		
		var nextID = getTermID() & "," & getCourseID() & "," & getCourseIndex();

		/* 
			主键生成规则 
			
			培养方案号18位 3位学期代码 , 6位课程号 , 3位课序号

			Unique: TERM_ID, CID, CIDX
		*/
		return nextID;
	}

}

</cfscript>